package com.jgy.juc.ticket;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 姜光远
 * @date 2023/3/7 22:02
 */
public class Windows implements Runnable{

     static int ticket = 150;

     ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            if (ticket<2){
                break;
            }else {
                lock.lock();
                try {
                    Thread.sleep(100);
                    --ticket;
                    System.out.println(Thread.currentThread().getName()+"卖出一张票，还剩"+ticket+"张票");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }
        }
    }
}
